// 约定一个通用的key(键名)
const INFO_KEY = 'smart_mall_info';
// 获取用户信息
export const getInfo = ()=>{
    const userInfo = localStorage.getItem(INFO_KEY)
    const defaultObj = {userId:'',token:''};
    return userInfo ? JSON.parse(userInfo) : defaultObj
}
// 设置用户信息 v
export const setInfo = (userInfo)=>{
    localStorage.setItem(INFO_KEY,JSON.stringify(userInfo))
}
// 移除用户信息
export const removeInfo = ()=>{
    localStorage.removeItem(INFO_KEY)
}

const HISTORY_KEY = 'history_info'
// 搜索历史记录持久化
//获取历史记录
export const getHistoryList = ()=>{
    const result = localStorage.getItem(HISTORY_KEY)
    return result ? JSON.parse(result) : [] 
}

//设置历史记录
export const setHistoryList = (historyArr)=>{
    localStorage.setItem(HISTORY_KEY,JSON.stringify(historyArr))
}